<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 二叉树实现结构
        function Node(value) {
            this.value = value;
            this.left = null;
            this.right = null;
        }
        var a = new Node(1)
        var b = new Node(null)
        var c = new Node(2)
        var d = new Node(3)
        a.left = b
        a.right = c
        b.left = d
        // 后序遍历-递归算法
        var postorderTraversal = function (root) {
            if (!root) return []
            let res = []
            traversal(root, res)
            return res
        }
        /* 
            1. 递归函数参数和返回值
            2. 递归退出条件
            3. 递归函数单层处理逻辑
        */
        function traversal (cur, res) {
            if (!cur) {
                return null
            }
            cur.left && traversal(cur.left, res)
            cur.right && traversal(cur.right, res)
            res.push(cur.value)
            return
        }
        console.log(postorderTraversal(a));



    </script>
</body>

</html>